<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition template="/template.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:c="http://java.sun.com/jsp/jstl/core">
    <ui:define name="title">
        <h:outputText value="#{bundle.ListUserGroupTitle}"></h:outputText>
    </ui:define>
    <ui:define name="body">
        <h:form id="display" styleClass="form list" rendered="#{userController.allowedGroups('1,2')}">
            <p:fieldset legend="User Group Control" >

                <c:if test="#{userController.allowedGroups('2')}">
                    <p:commandButton value="New Group" icon="ui-icon-plus" action="#{userGroupController.prepareCreate}" />
                </c:if>
                <p:separator/>
                <p:dataTable id="userGroup"
                             var="item"
                             widgetVar="table"
                             value="#{userGroupController.usersGroups}"
                             selection="#{userGroupController.current}"
                             rowKey="#{item}"
                             rows="15"
                             paginator="#{userGroupController.usersGroups.size() gt 14}"
                             selectionMode="single"
                             >
                    <f:facet name="header">
                        <h:outputText value="Group List"></h:outputText>
                    </f:facet>
                    <p:column sortBy="#{item.grDesc}" >
                        <f:facet name="header">
                            <h:outputText value="Description"/>
                        </f:facet>
                        <h:outputText value="#{item.grDesc}"/>
                    </p:column>
                    <f:facet name="footer">
                        <h:outputText id="rowCount"
                                      value="Total number of records: #{userGroupController.usersGroups.size()}" />
                        <br/>
                        <p:commandButton icon="ui-icon-plus" ajax="false" rendered="#{empty userGroupController.usersGroups}" action="#{userGroupController.prepareCreate}" value="New"/>
                    </f:facet>
                </p:dataTable>
                <br />

                <c:if test="#{userController.allowedGroups('2')}">
                    <p:contextMenu for="userGroup" >
                        <p:menuitem value="Edit" icon="ui-icon-pencil"  action="#{userGroupController.prepareEdit}" />
                        <p:menuitem value="Delete" icon="ui-icon-close" actionListener="#{userGroupController.destroy}" update="userGroup" />
                        <p:menuitem value="View" icon="ui-icon-search" action="#{userGroupController.prepareView}"/>
                        <p:menuitem value="New" icon="ui-icon-plus" action="#{userGroupController.prepareCreate}" />
                    </p:contextMenu>
                    <br/>
                </c:if>
            </p:fieldset>
        </h:form>
    </ui:define>
</ui:composition>


